<template>
    <div>
<h2>房号添加</h2>
<table class="table">
<tbody>
    <tr>
        <td>房间号</td>
        <td>
            <input type="text" v-model="model.Code">
        </td>
    </tr>

    <tr>
        <td>房型名称</td>
        <td>
            <input type="text" v-model="model.Name">
        </td>
    </tr>


    <tr>
        <td>备注</td>
        <td>
            <textarea  cols="35" rows="5" v-model="model.BeiZhu"></textarea>
           
        </td>
    </tr>


    <tr>
        <td>状态</td>
        <td>
            <input type="radio" v-model="model.State" value="1">上架
            <input type="radio" v-model="model.State" value="0">下架
        </td>
    </tr>


    <tr>
        <td></td>
        <td>
            <input type="button" value="添加" class="btn btn-success" @click="ok">
        </td>
    </tr>
</tbody>
</table>

    </div>
</template>

<script setup lang="ts">

import { ref,reactive } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

let model=reactive({
  "Code": '',
  "Name": '',
  "BeiZhu": '',
  "State": 1,
})


const ok=()=>{
axios({
url:'https://localhost:7190/api/House/HouseAdd',
method:'post',
data:model,
})

.then((res)=>{
console.log(res);
if(res.data==-1){
    alert('房间重复');
    return;
}
else if(res.data>0){

    alert('添加成功');
    router.push('/houseList')
    return;
}
else{
    alert('添加失败');
    
    return;
}


})

.catch((ree)=>{
console.log(ree);
})














}
</script>

<style scoped>

</style>